package com.bgrc.hubu12305.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bgrc.hubu12305.dao.TrainDao;
import com.bgrc.hubu12305.entity.ParkingStationEntity;
import com.bgrc.hubu12305.entity.TrainInfoEntity;
import com.bgrc.hubu12305.service.TrainService;
import com.bgrc.hubu12305.vo.TrainReturnVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 包名:com.bgrc.hubu12305.service.impl
 * 用户:86182
 * 时间:20211217:252021/12/15
 */
@Service
public class TrainServiceImpl extends ServiceImpl<TrainDao, TrainInfoEntity> implements TrainService {

    @Autowired
    private TrainDao trainDao;

    /**
     * 根据起始站和目的站查询车次
     * */

    @Override
    public List<TrainInfoEntity> getTrainListByStation(String startStation, String endStation) {
        QueryWrapper<TrainInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("train_start_station",startStation);
        queryWrapper.eq("train_end_station",endStation);
        queryWrapper.orderByAsc("train_start_time");
        List<TrainInfoEntity> list = this.list(queryWrapper);
        return list;
    }

    /**
     * 显示所有车次,分页
     * */
    @Override
    public List<TrainInfoEntity> getAllTrainPage(Integer currentPage) {
        QueryWrapper<TrainInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("train_start_time");
        Page<TrainInfoEntity> page = new Page<>(currentPage,5);
        List<TrainInfoEntity> records = this.page(page, queryWrapper).getRecords();
        return records;
    }

    /**
     * 得到车次运行总时间
     * */
    @Override
    public Integer getRunningTime(String trainNumber) {

        return trainDao.getRunningTime(trainNumber);
    }

    @Override
    public List<TrainInfoEntity> getAllTrain() {
        QueryWrapper<TrainInfoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("train_start_time");
        List<TrainInfoEntity> list = this.list(queryWrapper);
        return list;
    }

    @Override
    public Integer isExist(String trainNo) {
        return trainDao.isExist(trainNo);
    }

}
